#pragma once

#include<iostream>
#include<string>
#include<unistd.h>
#include<vector>
#include<unordered_map>
#include<functional>


//创建函数对象
typedef std::function<void()> func;
//使用vector容器，实现函数调用接口
vector<func> callbacks;
unordered_map<int,string> desc;

void read_my_sql() 
{
    cout<<"process:"<<getpid()<<"执行读取数据库任务"<<endl;
}

void execule_url()
{
    cout<<"process:"<<getpid()<<"执行url解析任务"<<endl;
}

void cal()
{
    cout<<"process:"<<getpid()<<"执行加密任务"<<endl;
}

void save()
{
    cout<<"process:"<<getpid()<<"执行保存数据任务"<<endl;
}

void load()
{
    desc.insert({callbacks.size(),"read_my_sql"});
    callbacks.push_back(read_my_sql);

    desc.insert({callbacks.size(),"execule_url"});
    callbacks.push_back(execule_url);

    desc.insert({callbacks.size(),"cal"});
    callbacks.push_back(cal);

    desc.insert({callbacks.size(),"save"});
    callbacks.push_back(save);
}

//显示系统接口总共提供了多少方法
void show_handler()
{
    for(const auto&iter:desc)
    {
        cout<<iter.first<<"\t"<<iter.second<<endl;
    }
}

//返回总共有多少个任务
int handler_size()
{
    return callbacks.size();
}